package com.haois.mp.wechat.handler;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * APP下载菜单点击事件处理器
 */
@Component
public class ContactMeHandler extends AbstractHandler implements WxMpMessageHandler {

    @Value("${defined.wxmp.cm-wechat}")
    private String wechat;
    @Value("${defined.wxmp.cm-tel}")
    private String tel;


    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> map, WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
        String content = this.execute(wxMpXmlMessage,wxMpService);
        return WxMpXmlOutMessage.TEXT()
                .fromUser(wxMpXmlMessage.getToUser())
                .toUser(wxMpXmlMessage.getFromUser())
                .content(content).build();
    }

    @Override
    public String execute(WxMpXmlMessage wxMpXmlMessage,WxMpService wxMpService) {
        String content = "微信☞ "+wechat + "\n" + "电话☞ "+tel;
        return content;
    }
}
